#include "GameObject.h"
#include "../Renderer/Renderer/Renderer.h"


CGameObject::CGameObject(void)
{
}

CGameObject::~CGameObject(void)
{
}

void CGameObject::Initialize(const char* szModelName)
{
	// Translate to world's center
	D3DXMatrixTranslation(&m_d3dObjectMatrix, 0, 0, 0);
	CRenderer::GetInstance()->GetModelInfo(szModelName, m_cObjectModel);
}

void CGameObject::Update(float fElapsedTime)
{
	D3DXMATRIX rotation;
	D3DXMatrixRotationY(&rotation, D3DXToRadian(70) * fElapsedTime);

	m_d3dObjectMatrix = rotation * m_d3dObjectMatrix;

	if(GetAsyncKeyState('A'))
	{
		m_d3dObjectMatrix._41 -= 5 * fElapsedTime;
	}
	if(GetAsyncKeyState('D'))
	{
		m_d3dObjectMatrix._41 += 5 * fElapsedTime;
	}

	if(GetAsyncKeyState('Q'))
	{
		m_d3dObjectMatrix._42 -= 5 * fElapsedTime;
	}
	if(GetAsyncKeyState('E'))
	{
		m_d3dObjectMatrix._42 += 5 * fElapsedTime;
	}

	if(GetAsyncKeyState('W'))
	{
		m_d3dObjectMatrix._43 += 5 * fElapsedTime;
	}
	if(GetAsyncKeyState('S'))
	{
		m_d3dObjectMatrix._43 -= 5 * fElapsedTime;
	}



	m_cObjectModel.GetMaterial().m_d3dObjectMatrix = m_d3dObjectMatrix;

	// After updating the materials push them into the renderer
	CRenderer::GetInstance()->AddModelToSet(m_cObjectModel);
	CRenderer::GetInstance()->AddLines(D3DXVECTOR3(2, 0, 2), D3DXVECTOR3(-10, 0, 5));
}

void CGameObject::MoveUp()
{
	D3DXMatrixTranslation(&m_d3dObjectMatrix, 2, 0, 2);
}